package com.siwei.mes.controller.system;

import com.siwei.mes.entity.system.TestProjectSpecConfig;
import com.siwei.mes.service.system.TestProjectSpecConfigService;
import org.springframework.web.bind.annotation.*;
import com.siwei.mes.common.query.PageQuery;
import com.siwei.mes.common.result.ApiResult;
import com.siwei.mes.common.result.Json;
import com.siwei.mes.common.validator.AddGroup;
import com.siwei.mes.common.validator.PageGroup;
import com.siwei.mes.common.validator.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.validation.annotation.Validated;

import static com.siwei.mes.common.exception.handler.MessageHandler.assertTrue;

import javax.annotation.Resource;
import java.util.List;

/**
 * 试验项目材料规格判定配置相关
 *
 * @author makejava
 * @since 2024-08-26 22:15:49
 */
@Api(value = "试验项目材料规格判定配置")
@RestController
@RequestMapping("testProjectSpecConfig")
public class TestProjectSpecConfigController {
    @Resource
    private TestProjectSpecConfigService testProjectSpecConfigService;

    @ApiOperation(value = "新增试验项目材料规格判定配置")
    @PostMapping("/create")
    public Json create(@RequestBody @Validated(AddGroup.class) TestProjectSpecConfig entity) {
        return Json.succ().data(ApiResult.addColumn("id", testProjectSpecConfigService.create(entity)));
    }

    @ApiOperation(value = "新增试验项目材料规格判定配置")
    @PostMapping("/batchCreate")
    public Json batchCreate(@RequestBody @Validated(AddGroup.class) List<TestProjectSpecConfig> entity) {
        return Json.succ().data(ApiResult.addColumn("id", testProjectSpecConfigService.batchCreate(entity)));
    }

    @ApiOperation(value = "修改试验项目材料规格判定配置")
    @PostMapping("/update")
    public Json update(@RequestBody @Validated(UpdateGroup.class) TestProjectSpecConfig entity) {
        testProjectSpecConfigService.update(entity);
        return Json.succ().data(new ApiResult());
    }
    @ApiOperation(value = "删除试验项目材料规格判定配置")
    @PostMapping("/delete")
    public Json delete(@RequestBody TestProjectSpecConfig entity) {
        testProjectSpecConfigService.delete(entity.getId());
        return Json.succ().data(new ApiResult());
    }
    @ApiOperation(value = "分页获取试验项目材料规格判定配置")
    @PostMapping("/page")
    public Json appPage(@RequestBody @Validated(PageGroup.class) PageQuery<TestProjectSpecConfig, TestProjectSpecConfig> query) {
        return Json.succ().data(testProjectSpecConfigService.getPage(query));
    }
    @ApiOperation(value = "根据主键id获取试验项目材料规格判定配置")
    @GetMapping("loadById")
    public Json loadById(@RequestParam("id") Long id) {
        return Json.succ().data(testProjectSpecConfigService.loadById(id));
    }
    @ApiOperation(value = "获取所有试验项目材料规格判定配置")
    @PostMapping("getAll")
    public Json getAll(@RequestBody TestProjectSpecConfig entity) {
        return Json.succ().data(ApiResult.addList(testProjectSpecConfigService.getAll(entity)));
    }

}
